package com.oocl.controller;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;


@Controller
public class UploadController {
	@RequestMapping(value = "/upload")  
    public String upload(@RequestParam(value="icfile",required=false) MultipartFile icfile,
    		@RequestParam(value="porfile",required = false) MultipartFile porfile, 
    		HttpServletRequest request, ModelMap model) {  
  
        System.out.println("开始");  
        String path = "D://img/";//request.getSession().getServletContext().getRealPath("upload");  
        String fileName = icfile.getOriginalFilename();  
//        String fileName = new Date().getTime()+".jpg";  
        System.out.println(path);  
        File targetFile = new File(path, fileName);  
        if(!targetFile.exists()){  
            targetFile.mkdirs();  
        }  
  
        //保存  
        try {  
        	icfile.transferTo(targetFile);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        System.out.println("结束");  
        //model.addAttribute("fileUrl", request.getContextPath()+"/upload/"+fileName);  
  
        return "index";  
    }  
}
